import random

_suiteList = ('s', 'h', 'd', 'c')
_numList = (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)
_totalCards = 52

class Deck:
	def __init__(self):
		self.deck = [] 
		self.cardsLeft = _totalCards 
		for s in _suiteList: 
			for n in _numList: 
				self.deck.append(Card(n, s)) 
				
	def shuffle(self): 
		self.cardsLeft = _totalCards 
		for i in range(1,100): 
			a = random.randint(0,51) 
			b = random.randint(0,51) 
			self.deck[a], self.deck[b] = self.deck[b], self.deck[a] 
			 
	def getCard(self): 
		index = _totalCards - self.cardsLeft 
		temp = self.deck[index] 
		self.cardsLeft -= 1 
		return temp 
		 
	def printDeck(self): 
		for card in self.deck:  
			card.printCard() 
		 
class Hand: 
	def __init__(self): 
		self.hand = [] 
		self.cardsLeft = 0 
		 
	def addCard(self, card): 
		if(self.cardsLeft <= 13): 
			self.hand.append(card) 
			self.cardsLeft += 1 
		else: 
			print("no more cards should have been distributed") 
			 
	def getCard(self, index): 
		return self.hand[index] 
		 
	def removeCard(self, index): 
		return self.hand.pop(index) 
		 
	def size(self): 
		return len(self.hand) 
		 
	def sortHand(self): 
		self.hand.sort() 
	
	def getHandList(self, delim):
		cstr = ""
		for card in self.hand:
			cstr += str(card) + delim
		cstr = cstr.rstrip(delim)
		return cstr
	
	def checkColor(self, color):
		for card in self.hand:
			if(card.suite == color):
				return True
		return False
	
	def __str__(self): 
		str = "" 
		for card in self.hand: 
			str += card.toString() + " " 
		return str 
		
	def __len__(self):
		return len(self.hand)
	def printHand(self, withNum):
		if(withNum):
			i = 0
			for card in self.hand:
				print(str(i) + ")" + str(card)),
				i += 1
		else:  
			print(self) 


class Card: 
	def __init__(self, n
				, s): 
		self.num = n 
		self.suite = s 

	def toString(self): 
		if self.num == 10: 
			return "t"+self.suite 
		elif self.num == 11: 
			return "J"+self.suite 
		elif self.num == 12: 
			return "Q"+self.suite 
		elif self.num == 13: 
			return "K"+self.suite 
		elif self.num == 14: 
			return "A"+self.suite 
		else: 
			return str(self.num)+self.suite 
		
	def __cmp__(self, card): 
		if(self.suite > card.suite): 
			return -1 
		elif(self.suite < card.suite): 
			return 1 
		else: 
			if(self.num < card.num): 
				return -1 
			elif(self.num > card.num): 
				return 1 
			else: 
				return 0		 

	def __str__(self): 
		return self.toString() 

	def printCard(self): 
		print(self), 

def str2Card(str): 
	num = str[0] 
	suite = str[1] 
	if(num == 't'): 
		return Card(10,suite) 
	elif(num == 'J'): 
		return Card(11,suite) 
	elif(num == 'Q'): 
		return Card(12,suite) 
	elif(num == 'K'): 
		return Card(13,suite) 
	elif(num == 'A'): 
		return Card(14,suite) 
	else:  
		return Card(int(num),suite) 
	

if(__name__ == '__main__'): 
	d = Deck() 
	d.printDeck() 
	d.shuffle() 
	print("") 
	d.printDeck() 
	print("") 
	h = Hand() 
	h.addCard(d.getCard()) 
	h.addCard(d.getCard()) 
	h.addCard(d.getCard()) 
	h.addCard(d.getCard()) 
	h.addCard(d.getCard()) 
	h.addCard(d.getCard()) 
	h.addCard(d.getCard()) 
	h.addCard(d.getCard()) 
	h.addCard(d.getCard()) 
	h.addCard(d.getCard()) 
	print("") 
	h.printHand(False) 
	h.sortHand() 
	print("") 
	h.printHand(False) 
	print("") 
	h.removeCard(2) 
	#h.printHand()
	
